Ext.define("wmf.view.channel.add", {
    extend: "wmf.lib.FormPanel",
    alias: "widget.channelAdd",
	anchor: '100% 100%',
    border: false,
    autoScroll: true,
    fieldDefaults: {
        labelWidth: 90
    },
    items: [{
        xtype: "textfield",
        allowBlank: false,
        name: "channelName", 
        fieldLabel: "通道名称"
    },{
    	fieldLabel: "所属运营商",
        xtype: 'combo',
		name: 'carrier',
		emptyText:  '请选择...',
		hiddenName: 'carrier',
		autoSelect: true,
		displayField: 'name',
		queryMode: 'local',
		valueField: 'carrier',
		triggerAction: 'all',
		allowBlank: false,
		editable: false,
		store: 'channel.carrier'
    },{
    	fieldLabel: "通道类型",
        xtype: 'combo',
		name: 'channelType',
		emptyText:  '请选择...',
		hiddenName: 'channelType',
		autoSelect: true,
		displayField: 'name',
		queryMode: 'local',
		valueField: 'channelType',
		triggerAction: 'all',
		allowBlank: false,
		editable: false,
		listeners : {
			'select': function(combo, records, eOpts){
				combo.up('panel').query('combo[name=capClassname]')[0].setValue('');
				combo.up('panel').query('combo[name=capName]')[0].setValue('');
				var pro = combo.up('panel').query('combo[name=protocalType]')[0];
				pro.setValue('');
				if(records[0].data.channelType == "1"){
					pro.getStore().loadData([{"name":"MM7", "protocalType":"MM7"}]);
				}else if(records[0].data.channelType == "2"){
					pro.getStore().loadData([{"name":"CMPP", "protocalType":"CMPP"},
					                         {"name":"HTTP", "protocalType":"HTTP"}]);
				}
			}
		},
		store: 'channel.channelType'
    },{
    	xtype: 'combo',
		emptyText:  '请选择...',
		hiddenName: 'protocalType',
		autoSelect: true,
		displayField: 'name',
		queryMode: 'local',
		valueField: 'protocalType',
		triggerAction: 'all',
		allowBlank: false,
		editable: false,
		store: 'access.protocalType',
        name: "protocalType", 
        listeners : {
        	'beforequery': function(qe){
        		delete qe.combo.lastQuery;
        	}
 		},
        fieldLabel: "协议类型"
    },{
        xtype: 'combo',
		emptyText:  '请选择...',
		hiddenName: 'billingType',
		autoSelect: true,
		displayField: 'name',
		queryMode: 'local',
		valueField: 'billingType',
		triggerAction: 'all',
		allowBlank: false,
		editable: false,
		store: 'channel.billingType',
        name: "billingType", 
        fieldLabel: "计费方式"
    },{
        xtype: "textfield",
        allowBlank: false,
        name: "channelPrice", 
        vtype: 'productPrice',
        fieldLabel: "通道价格"
    },{
    	xtype: 'combo',
		emptyText:  '请选择...',
		hiddenName: 'needSharing',
		autoSelect: true,
		displayField: 'name',
		queryMode: 'local',
		valueField: 'needSharing',
		triggerAction: 'all',
		allowBlank: false,
		editable: false,
		store: 'channel.needSharing',
        name: "needSharing", 
        fieldLabel: "是否分成"
    },{
        xtype: "textfield",
        //allowBlank: false,
        vtype: 'sharingRate',
        name: "sharingRate", 
        fieldLabel: "分成比例"
    },{
    	xtype: 'combo',
		emptyText:  '请选择...',
		hiddenName: 'className',
		autoSelect: true,
		displayField: 'capName',
		queryMode: 'remote',
		valueField: 'className',
		triggerAction: 'all',
		editable: false,
		minChars: 0,
 		forceSelection : true,
 		selectOnFocus : true,
        listeners : {
        	'beforequery': function(qe){
        		delete qe.combo.lastQuery;
        	}, 
        	'expand': function(combo, eOpts){
        		combo.store.clearFilter();
	    	    combo.store.filter({
	        		property     : 'classType',
	        		value        : '3',
	        		anyMatch     : true, //optional, defaults to true
	        		caseSensitive: false  //optional, defaults to true
	        	});  
	    	    combo.store.filter({
	        		property     : 'businessType',
	        		value        : combo.up('panel').getForm().getValues().channelType,
	        		anyMatch     : true, //optional, defaults to true
	        		caseSensitive: false  //optional, defaults to true
	        	});
	    	    combo.onLoad();
 			}
 		},
		store: 'channel.classUsage3',
        name: "capName", 
        fieldLabel: "流控能力接口"
    },{
        xtype: "textfield",
        vtype: 'numbers',
        name: "flowControl", 
        fieldLabel: "流量控制"
    },{
    	xtype: "textarea",
        name: "capBusiness", 
        vtype: 'capMax',
        fieldLabel: "处理模块业务参数"
    },{
        xtype: "textarea",
        name: "capStart", 
        fieldLabel: "启动参数"
    },{
    	xtype: 'combo',
		emptyText:  '请选择...',
		hiddenName: 'className',
		autoSelect: true,
		displayField: 'capClassname',
		queryMode: 'remote',
		valueField: 'className',
		triggerAction: 'all',
		editable: false,
		minChars: 0,
 		forceSelection : true,
 		selectOnFocus : true,
        listeners : {
        	'beforequery': function(qe){
        		delete qe.combo.lastQuery;
        	}, 
        	'expand': function(combo, eOpts){
            	combo.store.clearFilter();
	    	    combo.store.filter({
	        		property     : 'classType',
	        		value        : '2',
	        		anyMatch     : true, //optional, defaults to true
	        		caseSensitive: false  //optional, defaults to true
	        	});  
	    	    combo.store.filter({
	        		property     : 'businessType',
	        		value        : combo.up('panel').getForm().getValues().channelType,
	        		anyMatch     : true, //optional, defaults to true
	        		caseSensitive: false  //optional, defaults to true
	        	});
	    	    combo.onLoad();
 			}
 		},
		store: 'channel.classUsage2',
        name: "capClassname", 
        fieldLabel: "处理模块"
    }],
    
	dockedItems: [{
		xtype: 'toolbar',
		dock: 'bottom',
		layout: {
				type: 'hbox',
				alian: 'center',
				flex: 1
		},
		
		defaults: {
				xtype: 'button'
		},
		items: [{
			xtype : 'tbfill'
		},{
			itemId: 'save',
			icon: 'resources/icons/add.png',
			formBind: true,
			text: translations.global.operation.add
		},{
			itemId: 'reset',
			icon: 'resources/icons/icon_recover.png',
			text: translations.global.operation.reset
		},{
			itemId: 'cancel',
			icon : 'resources/icons/icon_revoke.png',
			text: translations.global.operation.cancel
		}]
	}]
});